const fun = (str) => {
    let res = [];
    let count = 1;
    let cur = str[0]
    for (let i = 1; i < str.length; i++) {
        if (str[i] == cur) {
            count++;
        } else {
            res.push(`${count}${cur}`)
            cur = str[i]
            count = 1
        }
    }
    return res.join('')
}
console.log(fun('aaabccddaa'))
// 3a1b2c2d2a